<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="/assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="/assets/css/admin/login.css">
    <link rel="stylesheet" href="../assets/utils/nprogress/nprogress.css">
    <script src="../assets/utils/nprogress/nprogress.js"></script>

</head>

<body>
    <script>
        NProgress.start()
    </script>
    <div class="bgc-cover"></div>
    <div class="login">
        <!-- 警告框 -->
        <!-- <div class="alert alert-danger" role="alert">
            <strong>错误！</strong>用户名或密码错误
            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
        </div > -->
        <div class="login-box">
            <div class="user-img">
                <img src="/assets/uploads/10.jpg" alt="">
            </div>
            <!-- 登录表单 -->
            <form>
                <div class="form-group">
                    <input id="email" type="email" class="form-control" placeholder="邮箱" autofocus>
                </div>
                <div class="form-group">
                    <input id="password" type="password" class="form-control" placeholder="密码" value="123456">
                </div>
                <button type="button" class="btn btn-primary login-btn">登 录</button>
            </form>
        </div>
    </div>
    <script src="/assets/js/jquery.min.js"></script>
    <script src="/assets/js/bootstrap.min.js"></script>
    <script>
        // 1、点击登录按钮
        $('.login-btn').on('click', () => {
            console.log('点击了登录');
            const email = $('#email').val()
            const pwd = $('#password').val()
            console.log(email + " -and- " + pwd);
            // 1-1没填表单
            if (email.trim().length == 0) {
                alert('请输入邮箱！')
                return
            }
            if (pwd.trim().length == 0) {
                alert('请输入密码！')
                return
            }
            // 1-2填了表单，掉接口
            $.ajax({
                type: 'post',
                url: '/login',
                data: {
                    email: email,
                    password: pwd
                },
                success: (res) => {
                    console.log(res);
                    location.href = 'index.html'

                },
                error: (err) => {
                    console.log('登录失败');
                    alert('用户名不存在或密码错误')

                }
            })


        })
    </script>
     <script>
        NProgress.done()
    </script>
</body>

</html>